package com.atguigu.ssyx.activity.controller;


import com.atguigu.ssyx.activity.service.ActivityInfoService;
import com.atguigu.ssyx.model.activity.ActivityInfo;
import com.atguigu.ssyx.model.activity.ActivityRule;
import com.atguigu.ssyx.model.product.SkuInfo;
import com.atguigu.ssyx.mq.result.Result;
import com.atguigu.ssyx.vo.activity.ActivityRuleVo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 活动表 前端控制器
 * </p>
 *
 * @author atguigu
 * @since 2023-11-09
 */
@RestController
//@CrossOrigin
@RequestMapping("/admin/activity/activityInfo")
public class ActivityInfoController {

    @Autowired
    private ActivityInfoService activityInfoService;

    //修改
    @PutMapping("update")
    @ApiOperation(value = "修改")
    public Result updateById(@RequestBody ActivityInfo activityInfo){
        activityInfoService.updateById(activityInfo);
        return  Result.ok(null);
    }

    //删除
    @DeleteMapping("remove/{id}")
    @ApiOperation(value = "单个删除")
    public Result removeById(@PathVariable("id") Long id){
        activityInfoService.removeById(id);
        return  Result.ok(null);
    }

    @DeleteMapping("batchRemove")
    @ApiOperation(value = "批量删除")
    public Result batchRemove(@RequestBody List<Long> ids){
        activityInfoService.removeByIds(ids);
        return  Result.ok(null);
    }


    //列表
    @GetMapping("{page}/{limit}")
    @ApiOperation(value = "列表")
    public Result list(@PathVariable Long limit, @PathVariable Long page){
        Page<ActivityInfo> pageParam = new Page<ActivityInfo>();
        IPage<ActivityInfo> pageModel=activityInfoService.selectPage(pageParam);
        return  Result.ok(pageModel);
    }
    //添加
    @PostMapping("save")
    @ApiOperation(value = "添加")
    public Result save(@RequestBody ActivityInfo activityInfo){
        activityInfoService.save(activityInfo);
        return  Result.ok(null);
    }

    //营销活动规则
    //1根据活动id获取活动规则接口
    @GetMapping("findActivityRuleList/{id}")
    @ApiOperation(value = "根据活动id获取活动规则接口")
    public Result findActivityRuleList(@PathVariable Long id){
        Map<String,Object> activityRuleMap =activityInfoService.findActivityRuleList(id);
        return  Result.ok(activityRuleMap);
    }
    //2在活动里面添加添加规则数据
    @PostMapping("saveActivityRule")
    @ApiOperation(value = "在活动里面添加添加规则数据")
    public Result saveActivityRule(@RequestBody ActivityRuleVo activityRuleVo){
        activityInfoService.saveActivityRule(activityRuleVo);
        return  Result.ok(null);
    }
    //3根据关键字查询匹配的sku信息
    @GetMapping("findSkuInfoByKeyword/{keyword}")
    @ApiOperation(value = "根据关键字查询匹配的sku信息")
    public Result findSkuInfoByKeyword(@PathVariable("keyword") String keyword){
        List<SkuInfo> skuInfoList = activityInfoService.findSkuInfoByKeyword(keyword);
        return  Result.ok(skuInfoList);
    }

    @GetMapping("get/{id}")
    public Result getSkuInfoById(@PathVariable("id") Long id){
        ActivityInfo activityInfo = activityInfoService.getById(id);
        activityInfo.setActivityTypeString(activityInfo.getActivityType().getComment());
        return Result.ok(activityInfo);
    }

    //删除单个

    //多个删除
}

